// Copyright 2013 Square, Inc.
package org.assertj.ohos.api.accessibilityservice;

import ohos.accessibility.AccessibilityAbilityInfo;
import org.assertj.core.api.AbstractAssert;
import static org.assertj.ohos.internal.BitmaskUtils.buildBitMaskString;
import static org.assertj.core.api.Assertions.assertThat;

/** Assertions for {@link AccessibilityAbilityInfo} instances. */
public class AccessibilityServiceInfoAssert
    extends AbstractAssert<AccessibilityServiceInfoAssert, AccessibilityAbilityInfo> {
  public AccessibilityServiceInfoAssert(AccessibilityAbilityInfo actual) {
    super(actual, AccessibilityServiceInfoAssert.class);
  }

  public AccessibilityServiceInfoAssert hasCapabilities(int capabilities) {
    isNotNull();
    int actualCapabilities = actual.getCapabilityValues();
    //noinspection ResourceType
    assertThat(actualCapabilities) //
        .overridingErrorMessage("Expected capabilities <%s> but was <%s>.",
            capabilitiesToString(capabilities), capabilitiesToString(actualCapabilities)) //
        .isEqualTo(capabilities);
    return this;
  }

  public AccessibilityServiceInfoAssert hasDescription(String description) {
    isNotNull();
    String actualDescription = actual.getDescription();
    assertThat(actualDescription) //
        .overridingErrorMessage("Expected description <%s> but was <%s>.", description,
            actualDescription) //
        .isEqualTo(description);
    return this;
  }

  public AccessibilityServiceInfoAssert hasId(String id) {
    isNotNull();
    String actualId = actual.getId();
    assertThat(actualId) //
        .overridingErrorMessage("Expected ID <%s> but was <%s>.", id, actualId) //
        .isEqualTo(id);
    return this;
  }

/*  // TODO: wang, not found in ohos
  public AccessibilityServiceInfoAssert hasSettingsActivityName(String name) {
    isNotNull();
    String actualName = actual.getSettingsActivityName();
    assertThat(actualName) //
        .overridingErrorMessage("Expected settings activity name <%s> but was <%s>.", name,
            actualName) //
        .isEqualTo(name);
    return this;
  }
*/

  public static String capabilitiesToString(int capabilities) {
    return buildBitMaskString(capabilities)
            // TODO: wang, not found in ohos
//        .flag(AccessibilityAbilityInfo.CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY, "request_enhanced_web_accessibility")
        .flag(AccessibilityAbilityInfo.CAPABILITY_FILTER_KEY_EVENTS, "filter_key_events") // TODO: wang, the flagName may change to others
        .flag(AccessibilityAbilityInfo.CAPABILITY_TOUCH_EXPLORATION, "touch_exploration") // TODO: wang, the flagName may change to others
        .flag(AccessibilityAbilityInfo.CAPABILITY_WINDOW_CONTENT, "window_content") // TODO: wang, the flagName may change to others
        .get();
  }
}
